package com.edu.zut.controller;


import com.edu.zut.domain.style.AbstractStyle;
import com.edu.zut.domain.style.CatalogStyle;
import com.edu.zut.domain.style.HeaderFooterStyle;
import com.edu.zut.domain.style.TableStyle;
import com.edu.zut.result.ResponseResult;
import com.edu.zut.service.PaperTemplateService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 论文模板表 前端控制器
 * </p>
 *
 * @author 许文科
 * @since 2023-01-12
 */
@RestController
@RequestMapping("/api/template")
public class PaperTemplateController {

    @Resource
    private PaperTemplateService templateService;

    @GetMapping("/list")
    @PreAuthorize("hasAnyRole('admin','teacher','student')")
    public ResponseResult list(@RequestParam("collegeName") String collegeName) {
        return templateService.getTemplateByCollegeName(collegeName);
    }

    @PostMapping("/table")
    @PreAuthorize("hasAnyRole('admin','teacher')")
    public ResponseResult table(@RequestBody TableStyle tableStyle) {
        return templateService.table(tableStyle);
    }

    @PostMapping("/header-footer")
    @PreAuthorize("hasAnyRole('admin','teacher')")
    public ResponseResult headerFooter(@RequestBody HeaderFooterStyle headerFooterStyle) {
        return templateService.headerFooter(headerFooterStyle);
    }

    @PostMapping("/abstract")
    @PreAuthorize("hasAnyRole('admin','teacher')")
    public ResponseResult abstractStyle(@RequestBody AbstractStyle abstractStyle) {
//        System.out.println(abstractStyle.toString());
        return templateService.abstractStyle(abstractStyle);
    }

    @PostMapping("/catalog")
    @PreAuthorize("hasAnyRole('admin','teacher')")
    public ResponseResult catalog(@RequestBody CatalogStyle catalogStyle) {
        return templateService.catalog(catalogStyle);
    }


}
